package aam.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import aam.model.member.MemberVO;
import aam.service.AdminService;
@Controller
public class AdminController 
{
	@Resource(name="adminServiceImpl")
	private AdminService adminService;
	
	@RequestMapping("/nickCheck.do")
	@ResponseBody
	public MemberVO nickCheck(String nick) throws Exception{
		MemberVO nvo=new MemberVO();
		nvo=adminService.nickCheck(nick);
		if(nvo==null){
			MemberVO nvo2=new MemberVO();
			nvo2.setId("");
			return nvo2;
		}
		return nvo;
	}
	
	@RequestMapping("/admin_point.do")
	public String loadingPoint() throws Exception
	{
		return "changepoint.admin";
	}
	
	@RequestMapping("/admin_updatePoint.do")
	public String updatePoint(String nick, String operator, int point)
	{
		System.out.println(nick + " " + operator + " " + point);
		adminService.updatePoint(nick, operator, point);
		return "pointupdate_ok.admin";
	}
	
	@RequestMapping("/admin_member.do")
	public ModelAndView adminMember() throws Exception{
		ModelAndView mv=new ModelAndView();
		mv.setViewName("membermanager.admin");
		List<MemberVO> memberList=adminService.memberList();
		mv.addObject("memberList",memberList);
		List<String> gradeList=adminService.gradeList();
		mv.addObject("gradeList",gradeList);
		return mv;
	}
	
	@RequestMapping("/admin_post.do")
	public ModelAndView loadingPost() throws Exception
	{
		List<String> list = adminService.getBoardList();
		return new ModelAndView("movepost.admin", "boardList", list);
	}
	
	@RequestMapping("/admin_movePost.do")
	public String movePost(int postNo, String boardName)
	{
		adminService.movePost(postNo, boardName);
		return "movepost_ok.admin";
	}
	
	@RequestMapping("/memberdelete.do")
	public String memberdelete(String id) throws Exception{
		int result= adminService.memberdelete(id);
		return "redirect:/admin_member.do";
	}
	
	@RequestMapping("/drawMember.do")
	@ResponseBody
	public int  drawMember(String id) throws Exception{
		int result=adminService.memberdelete(id);
		return result; 
	}
	
	@RequestMapping("/admin_updateMember.do")
	public String updateMember(MemberVO mvo) throws Exception{
		adminService.updateMember(mvo);
		return "redirect:/admin_member.do";
	}
}
